//
//  CXGiftCollectionViewCell.m
//  GiftThat
//
//  Created by ChuXiang on 16/1/8.
//  Copyright © 2016年 ChuXiang. All rights reserved.
//

#import "CXGiftCollectionViewCell.h"
//#import "LianDongView.h"
#import "LianDongView.h"
@interface CXGiftCollectionViewCell ()
@property (nonatomic, strong) LianDongView *lianView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) NSMutableArray *getArray;
@end
@implementation CXGiftCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        self.getArray = [NSMutableArray arrayWithCapacity:0];

        self.lianView = [[LianDongView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height - 113)];

        [self addSubview:self.lianView];
        
        //取消self. __weak
        __weak CXGiftCollectionViewCell *weakSelf = self;
        
        _lianView.myBlock = ^(NSMutableArray *array){
            NSMutableArray *data = [NSMutableArray arrayWithArray:array];
            [weakSelf.delegate pushViewWithUrlData:data];
        };
        

        [self getData];
        
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    self.lianView.frame = CGRectMake(0, 0, self.width, self.height - 113);
}

#pragma mark - GetData
- (void)getData {
    self.dataSource = [NSMutableArray arrayWithCapacity:0];
    [CXNetWorkTool getWithUrl:@"http://api.liwushuo.com/v2/item_categories/tree" parameter:nil httpHeader:nil responseType:ResponseTypeJSON success:^(id result) {
        if (result) {
            NSDictionary *dic = result[@"data"];
            NSArray *array = dic[@"categories"];
            for (NSDictionary *dic in array) {
                CXOUtModel *model = [[CXOUtModel alloc] initWithDictionary:dic];
                [self.dataSource addObject:model];
            }
            self.lianView.data = self.dataSource;

        }
    } fail:^(NSError *error) {
        NSLog(@"%@", error);
    }];
}

@end
